﻿/*
 * Created by SharpDevelop.
 * User: Михаил
 * Date: 11.01.2014
 * Time: 15:48
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using Region.Utils;
namespace Region.Forms
{
	/// <summary>
	/// Description of TaskWait.
	/// </summary>
	public partial class TaskWait : Form
	{
		Engine m_engine;
		public TaskWait(Engine engine)
		{
			//
			// The InitializeComponent() call is required for Windows Forms designer support.
			//
			InitializeComponent();
			m_engine = engine;
		}
		
		void Timer1Tick(object sender, EventArgs e)
		{
			Dictionary<Int32,TaskManager.Task> tl = m_engine.taskManager.RunTask;
			if (tl.Count>0)
			{
				foreach(TaskManager.Task t in tl.Values)
				{
					Int32 max = t.TaskMax;
					Int32 val = t.TaskValue;
					if (val>max) 
						val = max;
					if (progressBar1.Maximum != max) progressBar1.Maximum = max;
					if (progressBar1.Value != val) progressBar1.Value = val;
          if (label2.Text != t.TaskTitle) label2.Text = t.TaskTitle;
					if (label1.Text != t.TaskName) label1.Text = t.TaskName;
					if (t.Status == TaskManager.Task.EStatus.End)
						this.DialogResult = DialogResult.OK;
					break;
				}
			}
			else
			{
				this.DialogResult = DialogResult.OK;
			}
		}
	}
}
